<?php
/**
 * Created by PhpStorm.
 * User: jungshen
 * Date: 2019/2/26
 * Time: 14:07
 */

namespace app\api2\controller\other;


use app\api\controller\BasicApi;
use app\api\service\MemberService;
use service\FileService;
use think\Db;

class System extends BasicApi
{
    /**
     * 上传文件
     * @return \think\response\Json
     */
    public function upload_file()
    {
        try{
            $file = $this->request->file('file');
            if (!$file->checkExt(strtolower(sysconf('storage_local_exts')))) {
                return json(['msg' => '文件上传类型受限'],403);
            }
            // 文件上传处理
            if (($info = $file->move("static/upload"))) {
                $filename=$info->getSaveName();
                if ($url = FileService::getFileUrl($filename, 'local')) {
                    $data['data']['url']=str_replace('\\','/',$url);
                    $data['msg']='文件上传成功';
                    return json($data);
                }
            }
            return json(['msg' => '文件上传失败'],500);
        }catch (\Exception $e){
            return json(['msg' => $e->getMessage()],500);
        }
    }

    /**
     * 获取信用等级列表
     * @return \think\response\Json
     */
    function credit_list(){
        return json(['msg'=>'success','data'=>MemberService::credit_arr()]);
    }

    /**
     * 信息模块导航数据
     * @return \think\response\Json
     */
    function info_nav_data(){
        //找人数量
        $data['recruit_worker_num']=Db::name('recruit_worker')
            ->where('status',1)
            ->count();
        //询价数量
        $data['inquiry_num']=Db::name('inquiry')
            ->where('status',1)
            ->count();
        //采购数量
        $data['purchase_num']=Db::name('purchase')
            ->where('status',1)
            ->count();
        return json(['msg'=>'success','data'=>$data]);
    }

    /**
     * 获取会员统计数据
     * @return \think\response\Json
     */
    function member_data(){
        //查询工人邦数量
        $data['worker_num']=Db::name('worker_info')->count();
        //查询供应商数量
        $data['supplier_num']=Db::name('supplier_info')->count();
        //查询会员数量
        $data['member_num']=Db::name('store_member')->count();

        return json(['msg'=>'success','data'=>$data]);
    }

    /**
     * 获取分享图片的地址
     * @return \think\response\Json
     */
    function share_img(){
        $image=Db::name('system_ad')->where('id',22)->value('image');
        return json(['msg'=>'success','data'=>$image]);
    }

    function test(){

        //MemberService::rebate(30,1000,'您的下级用户[30]于['.date('Y/m/d H:i:s').']参与找人抢单，您获得分润');
    }


}